package strongholdCraft.common.Items.tool;

import net.minecraft.block.Block;
import net.minecraft.block.BlockSnow;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumToolMaterial;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemTool;
import net.minecraft.src.ModLoader;
import net.minecraft.world.World;

public class ItemShovel extends ItemTool {
	public static final Block[] blocksEffectiveAgainst = new Block[] {Block.grass, Block.dirt, Block.sand, Block.gravel, Block.snow, Block.blockSnow, Block.blockClay, Block.tilledField, Block.slowSand, Block.mycelium};
	public ItemShovel(int ID, EnumToolMaterial m, String name)
	{
	         super(ID, 1, m, blocksEffectiveAgainst);
	         setUnlocalizedName(name);
	}
	public boolean canHarvestBlock(Block par1Block)
	{
	         return par1Block == Block.snow ? true : par1Block == Block.blockSnow;
	}
	public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10)
	{
		for (int j = -1; j != 2; j++){
		for (int i = -1; i != 2; i++){
			if (	par3World.getBlockId(par4+i, par5, par6+j) == 2 || par3World.getBlockId(par4+i, par5, par6+j) == 3 || par3World.getBlockId(par4+i, par5, par6+j) == Block.sand.blockID || 
					par3World.getBlockId(par4+i, par5, par6+j) == Block.gravel.blockID || par3World.getBlockId(par4+i, par5, par6+j) == Block.snow.blockID || par3World.getBlockId(par4+i, par5, par6+j) == Block.blockSnow.blockID || 
					par3World.getBlockId(par4+i, par5, par6+j) == Block.blockClay.blockID || par3World.getBlockId(par4+i, par5, par6+j) == Block.tilledField.blockID || par3World.getBlockId(par4+i, par5, par6+j) == Block.slowSand.blockID || 
					par3World.getBlockId(par4+i, par5, par6+j) == Block.mycelium.blockID){
				if (par3World.getBlockId(par4+i, par5, par6+j) == 2){
					par2EntityPlayer.dropPlayerItem(new ItemStack(3,1,0));
					par3World.setBlock(par4+i, par5, par6+j, 0, 1, 0x02);
					par1ItemStack.damageItem(1, par2EntityPlayer);
				}else {
					if (par3World.getBlockId(par4+i, par5, par6+j) == Block.tilledField.blockID){
						par2EntityPlayer.dropPlayerItem(new ItemStack(3,1,0));
						par3World.setBlock(par4+i, par5, par6+j, 0, 1, 0x02);
						par1ItemStack.damageItem(1, par2EntityPlayer);
					}else {
						if (par3World.getBlockId(par4+i, par5, par6+j) == Block.blockSnow.blockID){
							par2EntityPlayer.dropPlayerItem(new ItemStack(Item.snowball.itemID,1,0));
							par3World.setBlock(par4+i, par5, par6+j, 0, 1, 0x02);
							par1ItemStack.damageItem(1, par2EntityPlayer);
						}else{
							par2EntityPlayer.dropPlayerItem(new ItemStack(par3World.getBlockId(par4+i, par5, par6+j),1,0));
							}
						par3World.setBlock(par4+i, par5, par6+j, 0, 1, 0x02);
						par1ItemStack.damageItem(1, par2EntityPlayer);
						}
					}
				}
			}
		}
		return false;
	} 
}


